# this just does all the calculations for standard deviation
from math import sqrt

#
# calculate the standard deviation of a specific number
#


def getStdDev(draw_list):
    draw_population = draw_list
    mean_list = getMeanSkip(draw_population)
    mean = mean_list[0]
    mean_count = mean_list[1]
    #
    # plug these into the variance calculator
    #
    variance = getVarianceSkip(draw_population, mean, mean_count)
    print ("Mean=" + str(mean) + " Count=" + str(mean_count) + " Variance="
    + str(variance))
    return sqrt(variance), mean

#
# calculate the mean
#
# draw_list is the list from the lottodb
#  a tuple consisting of number and the count of that number
#


def getMeanSkip(draw_population):
        # calculate the average skip count for all numbers
        mean_count = 0
        mean_total = 0
        mean = 0
        for pair in draw_population:
            mean_count += pair[1]
            mean_total += pair[0] * pair[1]
        if mean_count > 0:
            mean = mean_total / mean_count
        else:
            mean = 0
        return [mean, mean_count]

#
#calculate variance
#


def getVarianceSkip(draw_population, mean, count):
    #
    # variance = (value - mean) squared / count
    #
    total = 0
    for pair in draw_population:
        diffs = (pair[0] - mean) * (pair[0] - mean)
        total += diffs
    if count > 0:
        variance = total / count
    else:
        variance = 0
    return variance